var util = require('../../../utils/util.js')
var userid= ''//用户ID
var list=''//用户信息
var good_at=''//擅长领域
var newTime = ''//获取当前时间
var id = ''//用户id
const app = getApp()

Page({
  data: {
    ranking : [],//排名情况
    timedisplay:true,//时间显示
    newTimes:'',
  },
  onLoad:function(e){
    var that=this;
    //获取用户id
    wx.getStorage({
      key: 'userid',
      success: function (res) {
        that.setData({
          userid: res.data
        })
        //赋值
        id = that.data.userid
        console.log('=========' + id)
      },
    })
    //获取用户信息
    wx.request({
      url: 'http://10.20.58.235:8080/v1/open/information/manager/ranking',
      method:'GET',
      success:function(res){
        that.setData({
          list:res.data
        })
       console.log(that.data.list)
        //获取用户擅长领域
        wx.request({
          url: 'http://10.20.58.235:8080/v1/open/information/manager/area/%7Bid%7D?id=' + id,
          method: 'GET',
          header: {
            'content-type': 'application/json;charset=UTF-8 ',
          },
          success: function (res) {
            that.setData({
              good_at: res.data
            })
            console.log(that.data.good_at)

            //获取用户排名
            wx.request({
              url: 'http://10.20.58.235:8080/v1/open/information/manager/day/%7Bid%7D?id=' + id,
              method: 'GET',
              header: {
                'content-type': 'application/json;charset=UTF-8',
              },
              success: function (res) {
                console.log(res)
                //裁剪时间
                newTime = util.formatTime(new Date())
                console.log(newTime)
                for (var index in res.data) {
                  res.data[index].time = res.data[index].time.substring(0, 10);
                }
                that.setData({
                  newTimes: newTime
                })
                if (newTime == res.data[index].time) {
                  that.setData({
                    timedisplay: false
                  })
                } else {
                  that.setData({
                    timedisplay: true
                  })
                }
                that.setData({
                  ranking: res.data
                })
                console.log(res)
              }
            })
          }
        })
      }
    })
    
    
  }
})
